/*
 * Copyright (C) 2008 Shane Isbell
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.slideme.atom.parser;

import org.kxml2.io.KXmlParser;
import org.slideme.atom.parser.entity.AtomEntityContext;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;

public class Generator {

    private String uri;

    private String version;

    private String text;

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public static Generator marshalFrom(KXmlParser parser, AtomEntityContext ctx) throws IOException, XmlPullParserException {
        if (parser == null) {
            throw new IllegalArgumentException("parser");
        }
        Generator generator = new Generator();
        int attributeCount = parser.getAttributeCount();
        for (int i = 0; i < attributeCount; i++) {
            String name = parser.getAttributeName(i);
            if (name.equals("uri")) {
                generator.setUri(parser.getAttributeValue(i));
            } else if (name.equals("version")) {
                generator.setVersion(parser.getAttributeValue(i));
            }
        }
        generator.setText(parser.nextText());
        //parser.nextTag();
        return generator;
    }
}
